package com.compass.doctor.ui.setting

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import com.compass.doctor.databinding.ActivitySettingNotifyBinding
import com.compass.doctor.ui.setting.viewmodel.SettingNotifyViewModel
import com.compass.doctor.base.BaseVBActivity
import com.compass.framework.ext.onClick
import com.compass.framework.utils.LogUtil
import com.netease.yunxin.kit.common.ui.viewmodel.LoadStatus

/**
 * Description： 消息提醒设置
 * Date:2023/11/23 15:44
 */
class SettingNotifyActivity : BaseVBActivity<ActivitySettingNotifyBinding>() {

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, SettingNotifyActivity::class.java)
            context.startActivity(intent)
        }
    }

    private val notifyViewModel: SettingNotifyViewModel by viewModels()
    override fun initView(savedInstanceState: Bundle?) {
        //设置新消息通知
        mBinding.notifySc.isChecked = notifyViewModel.getToggleNotification()
        mBinding.notifySc.onClick {
            notifyViewModel.setToggleNotification(mBinding.notifySc.isChecked)
        }

        mBinding.notifyRingSc.isChecked = notifyViewModel.getRingToggle()
        mBinding.notifyRingSc.onClick {
            notifyViewModel.setRingToggle(mBinding.notifyRingSc.isChecked)
        }

        mBinding.notifyShakeSc.isChecked = notifyViewModel.getVibrateToggle()
        mBinding.notifyShakeSc.onClick {
            notifyViewModel.setVibrateToggle(mBinding.notifyShakeSc.isChecked)
        }

        //通知栏是否显示消息详情
        mBinding.notifyShowInfoSc.isChecked = !notifyViewModel.getPushShowNoDetail()
        mBinding.notifyShowInfoSc.onClick {
            notifyViewModel.setPushShowNoDetail(!mBinding.notifyShowInfoSc.isChecked)
        }
    }

    override fun initData() {
        notifyViewModel.notifyDetailLiveData.observe(this) { result ->
            LogUtil.e("loadStatus==$result.loadStatus${result.data}")
            if (result.loadStatus === LoadStatus.Error && result.data != null) {
                mBinding.notifyShowInfoSc.isChecked = !result.data!!
            }
        }

        notifyViewModel.toggleNotificationLiveDataLiveData.observe(this) { result ->
            if (result.loadStatus === LoadStatus.Error && result.data != null) {
                mBinding.notifySc.isChecked = !result.data!!
            }
        }

    }
}